<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums1, nums2) {
      let same = nums1.filter(a => nums2.includes(a))
      if (same.length) return Math.min(...same)
      return Math.min(Math.min(...nums1) * 10 + Math.min(...nums2), Math.min(...nums2) * 10 + Math.min(...nums1))
    };
    console.log(arr(nums1 = [4, 1, 3], nums2 = [5, 7]));
  </script>
</body>

</html>